﻿using System;
using System.Text;
using xBrainLab.Security.Cryptography;

namespace TestHMAC2
{
    class Program
    {
        static void Main(string[] args)
        {
            // CHALLENGE SAMPLES :
            var key1 = @"&kpHBTonCFpcAv4FAMx6ohOc4Q=Leoxbaarc-ae8L5ETrQqRkB3*PL6RLWW3joaN8B3ATJEgz=-jMgdwQAGw\S6f-3%e6\V*dkF+gbpX2H4aNARxOeCgSGVp&d*Qum4W";
            var challenge1 = @"HXrCTrEV&4h/=5p/wVh/ZGpmog7kqtfDC3Zj@mpT\4uyx=wAqX+rM$Hf6\Jb\mhScAT&RS-8X_KJ%D$xUoDn\-rJA\j4WKC/7mQYmN@YXp+dOGf3ORyaztUpHMzG+=n8";
            var token1 = @"oThH9657wsUCt2nbp9TlWA==";

            var key2 = @"-hnFB/YCtA\9AQ=fxs&nOVVbOb\?Wm%pYcqURe%ayLuP*ZW4TNPz@skVQj*5/LKbLo8$S4fM9\C%paghcVrMa?HsGsw7H*%Hpd$PmfLhjJHeie@u+ih=wVZc8pNeSGHM";
            var challenge2 = @"%pyH+gkCKEzJ7?N@PAgyS4ruV2%SzxoY=&O%ei9oAYijWKNxmX4xRkzkRNGd9NRNfmHm3FaK6CpRAAok%4R-Wi$@/nuq_YHENk-FGX_NyUw?darvdh__iG7DL_=7etur";
            var token2 = @"ApXfnSFW8sOV0KrRjgzhGw==";

            var key3 = @"kbBno-5Skm9@\iab9&K4P&b_V-BbmRegjd?kW8_U$dvuinGCfO$jQ-6fGr@$XDg*9hzcK%pfd5m$XKQabtpAjs53Vn-i&iLjbF_iXAfZ+Z*aLzJMbuJG*oPza7=PFUEe";
            var challenge3 = @"@oVy+CXrhkPpT+QsdMMZAT2*aAndsBiJdrpd6A\=eOzPL%u-F=ykp2Bdt&x\=&wPYb6JH@V3??@okojgFM7icS-33cAp_-su8Rd96Rc+ai=mQZvE/5mk3-R5pmeQFZf%";
            var token3 = @"+FuyBjbQZMB8RJ/KtqHPBg==";

            // Build the HMACMD5 with key1
            HMACMD5 hmac = new HMACMD5(key1);
            // ComputeHashToBase64String for challenge1 
            string computedHashString = hmac.ComputeHashToBase64String(challenge1);
            // Check with token1
            bool test = computedHashString == token1;
            
            // Change key to key2
            hmac.Key = Encoding.UTF8.GetBytes(key2);
            // ComputeHashToBase64String for challenge2 and check with token2
            test = hmac.ComputeHashToBase64String(challenge2) == token2;

            // Change key to key3
            hmac.Key = Encoding.UTF8.GetBytes(key3);
            // ComputeHashToBase64String for challeng3e and check with token3
            test = hmac.ComputeHashToBase64String(challenge3) == token3;

        }
    }
}
